﻿Imports System.Web.UI
Imports SISSAT.BusinessLayer.DomainModels
Imports SISSAT.BusinessLayer.Services

Namespace [Shared].UserControls
    Public Class CourseControl
        Inherits UserControl

        Private Property Service As ICourseService

        Property SelectedControlValue As String
            Get
                Return CoursesDropDownList.SelectedControlValue
            End Get
            Set(value As String)
                CoursesDropDownList.SelectedControlValue = value
            End Set
        End Property

        WriteOnly Property IsReadOnly As Boolean
            Set(value As Boolean)
                CoursesDropDownList.IsReadOnly = value
            End Set
        End Property

        Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
            Service = New CourseService

            Dim courses As IEnumerable(Of Course) = Service.ReadAll()
            CoursesDropDownList.DataSource = From course In courses
                                             Let courseId As String = Convert.ToString(course.CourseId)
                                             Select New KeyValuePair(Of String, String)(courseId, course.Name)
        End Sub

    End Class
End Namespace
